<?php
/*
Template Name: Prospress Index
*/
/**
 * The main template file for marketplace listings.
 * Uses a substitution method to run a wp_query for prospress posts and use native 'the loop' functions
 * 
 *
 * @package Prospress
 * @subpackage Theme
 * @since 0.1
 */
if( !class_exists( 'PP_Market_System' ) )
	die( 'This auctions index template has been improperly called before Prospress was able to activate.' );
 ?>

<?php get_header(); ?>
		<div id="container" class="prospress-container">
		<div id="content" class="prospress-content">
		<div class="pBox pListingsTitle"><h3>Prioritized Requests</h3></div>

<?php /* QAPRC Do we really need this loop? 
		<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
			<h1 class="prospress-title entry-title"><?php the_title(); ?></h1>
			<div class="prospres-content entry-content"><?php the_content(); ?></div>
			<div class="end-header"><?php _e( 'Time to go', 'prospress' ); ?></div>
			<div class="price-header"><?php _e( 'Price', 'prospress' ); ?></div>
			<div class="end-header"><?php _e( 'Priority', 'prospress' ); ?></div>
		<?php endwhile; ?>
	Do we really need this loop? */?>
		<div class="listing-header"><?php _e( 'Requested by', 'prospress' ); ?></div>
		<div class="listing-header"><?php _e( 'Time to go', 'prospress' ); ?></div>
		<div class="listing-header"><?php _e( 'Bids', 'prospress' ); ?></div>
		
		<?php global $wp_query,$paged; ?>
		<?php $_query = $wp_query; //store current query ?>
		<?php wp_reset_query(); //reset query to allow pagination and avoid possible conflicts ?>
		<?php 
			// This query is working to display records in desc order of priority_type meta_key, but to display 5 records from each priority Vij has commented this query and used next logic.		
			//$pp_loop = new WP_Query( array( 'posts_per_page' => 15,'post_type' => $market->name(), 'post_status' => 'publish', 'paged' => $paged,'orderby' => 'meta_value', 'meta_key' => 'priority_type' ,'order'=>'DESC' ) );
			$pp_loop = new WP_Query( array( 'posts_per_page' => 5,'post_type' => $market->name(), 'post_status' => 'publish','meta_key'=>'priority_type','meta_value'=>'Normal Priority','meta_compare'=> '!=', 'paged' => $paged) );
			$wp_query = $pp_loop;
		?>
		
		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
			  // check for priority type order ii , i and normal 
			  //if(get_post_meta(get_the_ID(), 'priorityTYPE',true)=='Priority Type I ')
			  
		?>
			<div class="pp-post">		
				<div class="pp-post-content"> 
					<div class="pp-price" id="pp-meta-<?=get_the_ID()?>"><?php echo get_the_author(get_the_ID(), 'author', true)?></div>
					<div class='pp-end' id="<?php echo get_post_end_time( get_the_ID(), 'timestamp', 'gmt' ); ?>">
						<?php the_post_end_time( '', 2, '<br/>' ); ?></div>	
					
					
					<!-- QAPRC: <div class="pp-price"><?php the_winning_bid_value(); ?></div> -->
				
					<h2 class="pp-title entry-title">
						<span class="urgentListing"> </span>
						<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
							<?php the_title(); ?>
						</a>
					</h2>	
					
					<?php /* QAPRC: there will be no picture for any request ("auction") 
						if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail() ) : ?>
						<div class="pp-thumbnail">
						   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
						   <?php the_post_thumbnail( array( 100,100 )); ?>
						   </a>
						</div>
					 <?php endif; */?>
					
						
					<div class="priority-type" id="pp-meta-<?=get_the_ID()?>"><?php echo get_post_meta(get_the_ID(), 'priority_type',true)?></div>
					
					<div class="pp-excerpt">
						<?php /* QAPRC deletes: the_excerpt(); */ ?>
						<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
							<?php printf( __( 'View %s &raquo', 'prospress' ), $market->labels[ 'singular_name' ] ); ?>
						</a>
					</div>
				</div>
			</div>

			<?php endwhile; else: ?>

			<p> No <?php echo $market->label; ?> </p>

		<?php endif; ?>
		<?php wp_reset_query(); //reset query to allow pagination and avoid possible conflicts ?>
		
		
		<div class="pBox pListingsTitle"><h3>Standard Requests</h3></div>
		<div class="listing-header"><?php _e( 'Requested by ', 'prospress' ); ?></div>
		<div class="listing-header"><?php _e( 'Time to go', 'prospress' ); ?></div>
		<div class="listing-header"><?php _e( 'Bids', 'prospress' ); ?></div>
		<?php $pp_loop = new WP_Query( array( 'posts_per_page' => 5,'post_type' => $market->name(), 'post_status' => 'publish','meta_key'=>'priority_type','meta_value'=>'Normal Priority','meta_compare'=>'=','paged' => $paged) );
			$wp_query = $pp_loop;
		?>	

		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
			  // check for priority type order ii , i and normal 
			  //if(get_post_meta(get_the_ID(), 'priorityTYPE',true)=='Priority Type I ')
			  
		?>
			<div class="pp-post">		
				<div class="pp-post-content"> 
					<div class="pp-price" id="pp-meta-<?=get_the_ID()?>"><?php echo get_the_author(get_the_ID(), 'author', true)?></div>
					<div class='pp-end' id="<?php echo get_post_end_time( get_the_ID(), 'timestamp', 'gmt' ); ?>">
						<?php the_post_end_time( '', 2, '<br/>' ); ?></div>	
					
					<!-- QAPRC: <div class="pp-price"><?php the_winning_bid_value(); ?></div> -->
				
					<h2 class="pp-title entry-title">
						<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
							<?php the_title(); ?>
						</a>
					</h2>
					
					<?php /* QAPRC: there will be no picture for any request ("auction") 
						if ( function_exists( 'has_post_thumbnail' ) && has_post_thumbnail() ) : ?>
						<div class="pp-thumbnail">
						   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
						   <?php the_post_thumbnail( array( 100,100 )); ?>
						   </a>
						</div>
					 <?php endif; */?>
					
						
					<div class="priority-type" id="pp-meta-<?=get_the_ID()?>"><?php echo get_post_meta(get_the_ID(), 'priority_type',true)?></div>
					
					<div class="pp-excerpt">
						<?php /* QAPRC deletes: the_excerpt(); */ ?>
						<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
							<?php printf( __( 'View %s &raquo', 'prospress' ), $market->labels[ 'singular_name' ] ); ?>
						</a>
					</div>
				</div>
			</div>

			<?php endwhile; else: ?>

				<p>No <?php echo $market->label; ?></p>

			<?php endif; ?>
			
			<?php if(function_exists('wp_paginate')) {
					wp_paginate();
			} ?>

			<?php wp_reset_query(); $wp_query = $_query; unset($_query); //restore original query and unset transient variable ?>
		</div>
	</div>

	<div id="sidebar" class="prospress-sidebar">
			<!-- QAPRC search form as default sidebar -->
				<form id="job-search" action="" method="POST">
				<div class="sidebarContainer">
				<h2>Show only Jobs with:</h2>
				<br>
				<input id="ytSolrJobSearch_fixedFee" type="hidden" value="" name="SolrJobSearch[fixedFee]"><input class="pCheckbox" name="SolrJobSearch[fixedFee]" id="SolrJobSearch_fixedFee" value="1" type="checkbox">    <label class="pLabel pCheckbox" for="SolrJobSearch_fixedFee">Fixed Fee</label>    <br>
				<input id="ytSolrJobSearch_hourlyContract" type="hidden" value="" name="SolrJobSearch[hourlyContract]"><input class="pCheckbox" name="SolrJobSearch[hourlyContract]" id="SolrJobSearch_hourlyContract" value="1" type="checkbox">    <label class="pLabel pCheckbox" for="SolrJobSearch_hourlyContract">Per Hour</label>
				<br>
					<select class="xoxo" name="SolrJobSearch[bidAge]" id="SolrJobSearch_bidAge">
						<option value="">Any Time</option>
						<option value="0">Bid accepted today</option>
						<option value="3">Bid accepted in 3 days</option>
						<option value="7">Bid accepted in 7 days</option>
					</select>    
						<select class="pSelect" name="SolrJobSearch[starting]" id="SolrJobSearch_starting">
							<option value="">All Posted Dates</option>
							<option value="0">Posted today</option>
							<option value="3">Posted in last 3 days</option>
							<option value="7">Posted in last 7 days</option>
							</select>
								<select class="pSelect" name="SolrJobSearch[category]" id="SolrJobSearch_category">
							<option value="">All Categories</option>
							<option value="17">Accounting/Legal</option>
							<option value="13">Personal</option>
							<option value="1">Organising/Planning</option>
							<option value="2">Admin/Secretarial</option>
							<option value="18">IT/Web/Programming</option>
							<option value="19">Design</option>
							<option value="20">Marketing/Sales/PR</option>
							<option value="21">Writing/Translation</option>
							<option value="12">Research</option>
							<option value="23">Photography/videography</option>
							<option value="22">Property</option>
							</select>
							<br>
							<br>
							<h2>Search</h2>
								<input class="text" name="SolrJobSearch[keyword]" id="SolrJobSearch_keyword" type="text" value="">    
								<input name="SolrJobSearch[type]" id="SolrJobSearch_type" type="hidden" value="awarded">
								<br>
								<br>
								<input type="submit" value="Search " class="buttonSmall buttonGeneric">
								&nbsp;&nbsp;
				 				<a href="/freelance-jobs/awarded">Reset</a>
							</div>
			</form>
	
		<ul class="xoxo">
			<li>
				<?php wp_loginout(); ?>
			</li>
			<li>
				<?php wp_register(); ?>
			</li>
		</ul>
	</div>
<?php get_footer(); ?> 

	
	
	
	